home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 12 / CU Amiga Magazine's Super CD-ROM 12 (1997)(EMAP Images)(GB)[!][issue 1997-07].iso / System / HappyENV / Extras / null.S < prev   
Text File  |  1996-06-18  |  5KB  |  267 lines

  1. *************************
  2. *    NULL-Handler    *
  3. *    12.11.95    *
  4. * (C) Martin Gierich    *
  5. *************************
  6.  
  7. * Mountlist entry looks like:
  8. *
  9. * ENV:
  10. *     Handler = L:ENV-Handler
  11. *     Stacksize = 2000
  12. *     Priority = 5
  13. *     GlobVec = -1
  14. * #
  15.  
  16.  
  17. DEBUG    = 1
  18.  
  19.     INCDIR    source:stripinc/
  20.     INCLUDE    exec/exec_lib.i
  21.     INCLUDE    dos/dos_lib.i
  22.     INCLUDE    dos/dosextens.i
  23.     INCLUDE    dos/filehandler.i
  24.  
  25. CALL    MACRO
  26.     jsr    _LVO\1(a6)
  27.     ENDM
  28.  
  29.     IFD    DEBUG
  30. DBUG1    MACRO
  31.     movem.l    d0-d7/a0-a6,-(sp)
  32.     move.l    \2,-(sp)
  33.     lea.l    \1(pc),a0
  34.     lea.l    (sp),a1
  35.     lea    RawHook(pc),a2
  36.     move.l    4.w,a6
  37.     jsr    _LVORawDoFmt(a6)
  38.     addq.l    #4,sp
  39.     movem.l    (sp)+,d0-d7/a0-a6 
  40.     ENDM
  41.  
  42. DBUG0    MACRO
  43.     movem.l    d0-d7/a0-a6,-(sp)
  44.     lea.l    \1(pc),a0
  45.     lea    RawHook(pc),a2
  46.     move.l    4.w,a6
  47.     jsr    _LVORawDoFmt(a6)
  48.     movem.l    (sp)+,d0-d7/a0-a6 
  49.     ENDM
  50.     ENDC
  51.  
  52.     IFND    DEBUG
  53. DBUG1    MACRO
  54.     ENDM
  55. DBUG0    MACRO
  56.     ENDM
  57.     ENDC
  58.  
  59. mn_Node        = 0
  60. fh_Port        = 4
  61. DOS_TRUE    = -1
  62. DOS_FALSE    = 0
  63. _LVORawPutChar    = -516
  64.  
  65.  
  66. ;private main structure
  67.         RSRESET
  68. MyProcess    RS.L    1
  69. MyMsgPort    RS.L    1
  70. MyPacket    RS.L    1
  71. MyDeviceNode    RS.L    1
  72. MyFileHandle    RS.L    1
  73. OpenCount    RS.L    1
  74. MyStructSize    RS.W    0
  75.  
  76.  
  77. *******************************************************
  78.  
  79. ;a5=private struct
  80. ;a6=execbase
  81. start:    movem.l    d2-d7/a2-a6,-(sp)
  82.     DBUG0    txstart
  83.     move.l    4.w,a6
  84.     moveq    #MyStructSize,d0
  85.     moveq    #1,d1
  86.     CALL    AllocMem
  87.     tst.l    d0
  88.     beq    exit
  89.     move.l    d0,a5
  90.  
  91.     sub.l    a1,a1
  92.     CALL    FindTask
  93.     move.l    d0,MyProcess(a5)
  94.     move.l    d0,a0
  95.     bset    #0,pr_Flags+3(a0)
  96.     add.l    #pr_MsgPort,d0
  97.     move.l    d0,MyMsgPort(a5)
  98.     clr.l    OpenCount(a5)
  99.  
  100.     bsr    GetPacket    process startup message
  101.     move.l    MyPacket(a5),a1
  102.     move.l    dp_Arg3(a1),d0
  103.     lsl.l    #2,d0
  104.     move.l    d0,MyDeviceNode(a5)
  105.     move.l    d0,a0
  106.     move.l    MyMsgPort(a5),dn_Task(a0)
  107.     clr.l    dn_SegList(a0)
  108.     moveq    #DOS_TRUE,d0
  109.     move.l    d0,dp_Res1(a1)
  110.     bsr    ReplyPacket
  111.     DBUG0    txed
  112.  
  113. loop    bsr    GetPacket
  114.     move.l    MyPacket(a5),a0
  115.     moveq    #DOS_TRUE,d0
  116.     move.l    d0,dp_Res1(a0)
  117.     move.l    dp_Type(a0),d0
  118.     cmp.l    #ACTION_FINDINPUT,d0
  119.     bne.s    .A
  120.     bsr    OpenOldfile
  121.     bra    loopend
  122. .A    cmp.l    #ACTION_FINDOUTPUT,d0
  123.     bne.s    .C
  124.     bsr    OpenNewfile
  125.     bra    loopend
  126. .C    cmp.l    #ACTION_END,d0
  127.     bne.s    .D
  128.     bsr    CloseFile
  129.     bra    loopend
  130. .D    cmp.l    #ACTION_READ,d0
  131.     bne.s    .E
  132.     bsr    ReadFile
  133.     bra    loopend
  134. .E    cmp.l    #ACTION_WRITE,d0
  135.     bne.s    .F
  136.     bsr    WriteFile
  137.     bra    loopend
  138. .F    cmp.l    #ACTION_DIE,d0
  139.     beq    exit2
  140.     DBUG1    txerr1,d0
  141.     move.l    MyPacket(a5),a0
  142.     clr.l    dp_Res1(a0)
  143.     move.l    #ERROR_ACTION_NOT_KNOWN,dp_Res2(a0)
  144. loopend    bsr    ReplyPacket
  145.     bra    loop
  146.  
  147. exit2    DBUG0    txend
  148.     bsr    ReplyPacket
  149.     tst.l    OpenCount(a5)
  150.     beq.s    .A
  151.     bpl    loop
  152. .A    bsr    FlushPackets
  153.     move.l    MyDeviceNode(a5),a0
  154.     clr.l    dn_Task(a0)
  155.     move.l    a5,a1
  156.     moveq    #MyStructSize,d0
  157.     CALL    FreeMem
  158.     DBUG0    txed
  159. exit    movem.l    (sp)+,d2-d7/a2-a6
  160.     moveq    #0,d0
  161.     rts
  162.  
  163. *******************************************************
  164.  
  165. * Wait for a packet then get it into MyPacket
  166. GetPacket:
  167. .A    move.l    MyMsgPort(a5),a0
  168.     CALL    WaitPort
  169.     move.l    MyMsgPort(a5),a0
  170.     CALL    GetMsg
  171.     tst.l    d0
  172.     beq.s    .A
  173.     move.l    d0,a0
  174.     move.l    mn_Node+LN_NAME(a0),MyPacket(a5)
  175.     beq.s    .A
  176.     rts
  177.  
  178. * Reply packet in MyPacket
  179. ReplyPacket:
  180.     move.l    MyPacket(a5),a2
  181.     move.l    dp_Port(a2),a0        reply port
  182.     move.l    dp_Link(a2),a1        message to send
  183.     move.l    MyMsgPort(a5),dp_Port(a2)
  184.     move.l    a2,mn_Node+LN_NAME(a1)
  185.     clr.l    mn_Node+LN_SUCC(a1)
  186.     clr.l    mn_Node+LN_PRED(a1)
  187.     CALL    PutMsg
  188.     rts
  189.  
  190. FlushPackets:
  191. .A    move.l    MyMsgPort(a5),a0
  192.     CALL    GetMsg
  193.     tst.l    d0
  194.     beq.s    .C
  195.     move.l    d0,a0
  196.     move.l    mn_Node+LN_NAME(a0),MyPacket(a5)
  197.     beq.s    .A
  198.     move.l    MyPacket(a5),a0
  199.     clr.l    dp_Res1(a0)
  200.     move.l    #ERROR_ACTION_NOT_KNOWN,dp_Res2(a0)
  201.     bsr    ReplyPacket
  202.     bra.s    .A
  203. .C    rts
  204.  
  205. *******************************************************
  206.  
  207. OpenOldfile:
  208.     move.l    MyPacket(a5),a1
  209.     DBUG1    txopeno,dp_Arg3(a1)
  210.     move.l    dp_Arg1(a1),a0
  211.     add.l    a0,a0
  212.     add.l    a0,a0
  213.     clr.l    fh_Port(a0)
  214.     addq.l    #1,OpenCount(a5)
  215.     rts
  216.  
  217. OpenNewfile:
  218.     move.l    MyPacket(a5),a1
  219.     DBUG1    txopenn,dp_Arg3(a1)
  220.     move.l    dp_Arg1(a1),a0
  221.     add.l    a0,a0
  222.     add.l    a0,a0
  223.     clr.l    fh_Port(a0)
  224.     addq.l    #1,OpenCount(a5)
  225.     rts
  226.  
  227. CloseFile:
  228.     DBUG0    txclose
  229.     subq.l    #1,OpenCount(a5)
  230.     rts
  231.  
  232. ReadFile:
  233.     move.l    MyPacket(a5),a1
  234.     DBUG0    txread
  235.     moveq    #0,d0
  236.     move.l    d0,dp_Res1(a1)
  237.     subq.l    #1,OpenCount(a5)
  238.     rts
  239.  
  240. WriteFile:
  241.     move.l    MyPacket(a5),a1
  242.     DBUG1    txwrite,dp_Arg3(a1)
  243.     move.l    dp_Arg3(a1),dp_Res1(a1)
  244.     subq.l    #1,OpenCount(a5)
  245.     rts
  246.  
  247. *******************************************************
  248.  
  249.     IFD    DEBUG
  250. RawHook    move.l    a6,-(sp)
  251.     move.l    4.w,a6
  252.     jsr    _LVORawPutChar(a6)
  253.     move.l    (sp)+,a6
  254.     rts
  255.  
  256. txstart    dc.b    "Handler start",0
  257. txend    dc.b    "Handler end",0
  258. txed    dc.b    "ed",10,0
  259. txerr1    dc.b    "%ld: Action not known",10,0
  260. txopeno    dc.b    "Open old file %b",10,0
  261. txopenn    dc.b    "Open new file %b",10,0
  262. txclose    dc.b    "Close file",10,0
  263. txread    dc.b    "Read access",10,0
  264. txwrite    dc.b    "Write %ld bytes",10,0
  265.     ENDC
  266.  
  267.